package com.itheima.collecton.list.linklist;

import java.util.LinkedList;

public class MyLinkListDemo1 {
    public static void main(String[] args) {
        LinkedList<String> list = new LinkedList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");

        System.out.println(list);

        System.out.println("---------------------------");

        method1(list);

        method2(list);

        method3(list);
    }

    public static void method3(LinkedList<String> list) {
        String first = list.getFirst();
        System.out.println("first = " + first);
        String last = list.getLast();
        System.out.println("last = " + last);
    }

    public static void method2(LinkedList<String> list) {
        //E removeFirst()    返回并删除列表中的第一个元素
        String first = list.removeFirst();
        System.out.println("first = " + first);
        //E removeLast()    返回并删除列表的最后一个元素
        String last = list.removeLast();
        System.out.println("last = " + last);
        System.out.println(list);
        System.out.println("---------------------------");
    }

    public static void method1(LinkedList<String> list) {
        //void addFirst(E e)    再列表的起始位置添加一个元素
        list.addFirst("first");
        //void addList(E e)    再列表的末尾位置添加一个元素
        list.addLast("last");
        System.out.println(list);
        System.out.println("---------------------------");
    }
}
